<?php
/* @var $this ProductController */
/* @var $model Product */

$this->breadcrumbs=array(
	'综合控制台'=>array($this->pre_module_url.'/index/index'),
	'产品管理'=>array($this->pre_module_url.'/productSale/admin'),
	'宝贝推荐'=>array($this->pre_module_url.'/product/recommend'),
	'促销推荐',
);
?>
<div class="pro_filter c_f">
		<?php $form=$this->beginWidget('CActiveForm', array(
			'action'=>Yii::app()->createUrl($this->route),
			'method'=>'get',
		)); ?>
			<?php echo CHtml::hiddenField('zpoid',Yii::app()->request->getParam('zpoid',0));?>
			<?php echo CHtml::hiddenField('type',$type)?>
			<?php echo CHtml::textField('CmpPromotion[zcr_title]',empty($product->zcr_title)?'请输入关键字':$product->zcr_title,array('class'=>'t_ipt w_170','onfocus'=>"if (value =='请输入关键字'){value =''}",'onblur'=>"if (value ==''){value='请输入关键字'}"))?>
			<?php echo CHtml::submitButton(Yii::t('adm','Search'),array('class'=>'mem_bgx mem_btn01')); ?>
		<?php $this->endWidget(); ?>
</div>
<div class="recommend_box">
    <div class="hd mem_bgx">设置显示时间</div>
    <ul class="form_list">
        <li><span class="tit">开始时间：</span> <?php echo CHtml::textField('start',date('Y-m-d',time()),array('onclick'=>"WdatePicker()"))?> </li>
        <li><span class="tit">结束时间：</span> <?php echo CHtml::textField('end','',array('onclick'=>"WdatePicker()"))?> </li>
    </ul>
    <div class="hd mem_bgx">选择推荐内容（限时打折）</div>
    <table class="list_table list_table2" width="100%" cellpadding="0" cellspacing="0">
        <tr class="bgcolor">
            <th width="">活动标题</th>
            <th width="45%">商家名称</th>
            <th width="22%">操作</th>
        </tr>
        <?php $list = $this->beginWidget('zii.widgets.CListView', array(
                            'dataProvider'=>$product->search(),
                            'itemView'=>'_addrecommenddiscount',
                            'template'=>'',
                            'viewData'=>array('ids'=>$ids,'type'=>$type),
                        )); ?>
        <?php $list->renderItems();?>
        <tr class="foot">
            <td colspan="3"><?php $list->renderPager();?></td>
        </tr>
        <?php $this->endWidget();?>
    </table>
</div>
<script language="javascript" type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/My97DatePicker/WdatePicker.js"></script> 
<script language="javascript">
	//推荐产品
	function recommend(zpoid,zpid,type){
		var start = $('#start').val();
		var end   = $('#end').val();
		$.ajax({
			type: "POST",
			url: "/manage/product/dorecommendajax",
			dataType:"json",
			data: "zpoid="+zpoid+"&zpid="+zpid+"&start="+start+"&end="+end+"&type="+type,
			success: function(data){
				switch(data.code){
					case 1: //alert( "推荐提示：推荐成功！");
					$('#recommend'+data.zpid).hide();
					$('#recommended'+data.zpid).show();
					break;
					case 2: alert( "推荐提示：时间设置错误，请设置正确的开始和结束时间！");
					break;
					case 3: alert( "推荐提示：内容已满！");
					break;
					case 4: alert( "推荐提示：内容已推荐");
					break;
					case 5: alert( "推荐提示：产品不存在或不可推荐！");
					break;
					case 6: alert( "推荐提示：推荐位不存在！");
					break;
					case 7: alert( "推荐提示：推荐失败！");
					break;
					case 8: alert( "推荐提示：参数错误，请重试！");
					break;
					default:;
					break;
				}	 
		   }
		});
	}
	//取消推荐
	function unRecommend(zpoid,zpid){
		$.ajax({
			type: "POST",
			url: "/manage/product/unrecommendajax",
			dataType:"json",
			data: "zpoid="+zpoid+"&zpid="+zpid,
			success: function(data){
				switch(data.code){
					case 1: //alert( "操作提示：取消成功！");
					$('#recommend'+data.zpid).show();
					$('#recommended'+data.zpid).hide();
					break;
					case 2: alert( "该内容不存在！");
					break;
					default:;
					break;
				}	 
		   }
		});
	}
</script>
<script type="text/javascript" src="/js/multi_select.js"></script>
<script type="text/javascript">
$.getJSON('/cache/GetCategory',function(json){
	var options	= {data	: json};
	var loc = new multi_select(options);
	loc.bind('#catagory .level_1','<?php if(!empty($category)) echo ($category->zca_topid>0)?$category->zca_topid:(($category->zca_parentid>0)?$category->zca_parentid:$category->zca_id)?>');
	loc.bind('#catagory .level_2','<?php if(!empty($category)) echo ($category->zca_topid>0)?$category->zca_parentid:(($category->zca_parentid>0)?$category->zca_id:'')?>');
	loc.bind('#catagory .level_3','<?php if(!empty($category)) echo ($category->zca_topid>0)?$category->zca_id:''?>');
});
</script>